//log
eclipse.runtime.include("../log/log.eclipse.js");
log.log('include Stack');

/**
 * 栈
 */
var Stack = function() {
	var cache = [];
	// 进栈
	this.put = function() {
		arguments.length ? Array.prototype.push.apply(cache, Array.prototype.slice.call(arguments)) : '';
	}
	// 出栈
	this.get = function() {
		return cache.pop();
	}
	// 最后一项
	this.last = function() {
		return this.empty() ? null : cache[this.size() - 1];
	}
	// 栈长度
	this.size = function() {
		return cache.length;
	}
	// 栈是否为空
	this.empty = function() {
		return this.size() === 0;
	}
	// 栈清空
	this.clear = function() {
		cache.length = 0;
	}
	// 栈快照
	this.copy = function() {
		return cache.slice();
	}
};

/*
 * log.switchover(true); var a = new Stack(); a.put(1); a.put(2);
 * log.log(a.size() == 2); a.put(3, 4); log.log(a.size() == 4); log.log(a.get()
 * === 4); log.log(a.last() === 3); log.log(a.size() === 3);
 * log.log(!a.empty()); log.log(a.copy().length == 3); log.log(a.size() === 3);
 * a.clear(); log.log(a.size() == 0);
 */
